package com.hui;

import org.springframework.batch.core.JobExecution;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.job.flow.FlowExecutionStatus;
import org.springframework.batch.core.job.flow.JobExecutionDecider;

import java.util.Objects;

/**
 * @author Zhang zhongtao
 * @version 1.0.0.20181117
 * @since JDK V1.8
 */
public class StepDecider implements JobExecutionDecider {

    private Boolean flag;

    public StepDecider(Boolean flag) {
        this.flag = flag;
    }

    @Override
    public FlowExecutionStatus decide(JobExecution jobExecution, StepExecution stepExecution) {

        String statusName = "";

        if (Objects.equals(stepExecution.getStepName(), "springbatch-learn-9_step1")) {
            statusName = "springbatch-learn-9_step2";
        } else if (Objects.equals(stepExecution.getStepName(), "springbatch-learn-9_step2")) {
            statusName = "springbatch-learn-9_step3";
        } else if (Objects.equals(stepExecution.getStepName(), "springbatch-learn-9_step3")) {
            statusName = "TRUE";
        } else {
            statusName = "springbatch-learn-9_step1";
        }

        return new FlowExecutionStatus(statusName);

    }

}
